package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqAlarmResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;

import java.util.List;

public class DelAlarmReceiver implements Receiver {
    @Override
    public String parseMessage(String data) {
        //*TJ,IMEI,V4, DELCLOCK,HHMMSS,sequence，DeviceTime,A,2212.8745,N,11346.6574,E,14.28,028,DeviceDate,FFFFFFFF#
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];
        String sequence = split[5];
        String deviceTime = split[6];
        String latitude = split[8];
        String longitude = split[10];
        String speed = split[12];
        String orientation = split[13];
        String deviceDate = split[14];
        List<Double> list = LocationUtils.transiformLatAndLng(longitude, latitude);
        MqAlarmResult result=new MqAlarmResult();
        result.setCommandNumber(commandNumber);
        result.setDeviceDate(deviceDate);
        result.setDeviceTime(deviceTime);
        result.setImei(imei);
        result.setSequence(Integer.valueOf(sequence));
        MqLocationData mqLocationData=new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        result.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().delAlarmReply(result);
        return imei;
    }
}
